package org.laobai.shop.protal.controller;

import javax.validation.Valid;

import org.apache.dubbo.config.annotation.DubboReference;
import org.laobai.shop.user.entity.User;
import org.laobai.shop.user.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("user")
public class UserController {
	@DubboReference
	private UserService userService;
	@RequestMapping("toReg")
	public String toReg(Model model){
		model.addAttribute("user",new User());
		return "register";
	}
	@RequestMapping("reg")
	public String reg(@Valid @ModelAttribute("user") User user,BindingResult result){
		if(result.hasErrors()){
			System.out.println("---------------------------------------------------");
			return "register";
		}
		return userService.register(user)? "login":"register";
		
	}
	
}
